home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / MAKE3761.LZH / info / make.info-2 < prev    next >
Encoding:
GNU Info File  |  1998-07-20  |  50.1 KB  |  1,226 lines

  1. This is Info file make.info, produced by Makeinfo version 1.67 from the
  2. input file make.texinfo.
  3.  
  4. INFO-DIR-SECTION The GNU make utility
  5. START-INFO-DIR-ENTRY
  6. * GNU make: (make.info).           The GNU make utility.
  7. END-INFO-DIR-ENTRY
  8.  
  9.    This file documents the GNU Make utility, which determines
  10. automatically which pieces of a large program need to be recompiled,
  11. and issues the commands to recompile them.
  12.  
  13.    This is Edition 0.51, last updated 26 Aug 1997, of `The GNU Make
  14. Manual', for `make', Version 3.76 Beta.
  15.  
  16.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96, '97     Free
  17. Software Foundation, Inc.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that
  25. the entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Free Software Foundation.
  32.  
  33. File: make.info,  Node: Rule Example,  Next: Rule Syntax,  Up: Rules
  34.  
  35. Rule Example
  36. ============
  37.  
  38.    Here is an example of a rule:
  39.  
  40.      foo.o : foo.c defs.h       # module for twiddling the frobs
  41.              cc -c -g foo.c
  42.  
  43.    Its target is `foo.o' and its dependencies are `foo.c' and `defs.h'.
  44. It has one command, which is `cc -c -g foo.c'.  The command line
  45. starts with a tab to identify it as a command.
  46.  
  47.    This rule says two things:
  48.  
  49.    * How to decide whether `foo.o' is out of date: it is out of date if
  50.      it does not exist, or if either `foo.c' or `defs.h' is more recent
  51.      than it.
  52.  
  53.    * How to update the file `foo.o': by running `cc' as stated.  The
  54.      command does not explicitly mention `defs.h', but we presume that
  55.      `foo.c' includes it, and that that is why `defs.h' was added to
  56.      the dependencies.
  57.  
  58. File: make.info,  Node: Rule Syntax,  Next: Wildcards,  Prev: Rule Example,  Up: Rules
  59.  
  60. Rule Syntax
  61. ===========
  62.  
  63.    In general, a rule looks like this:
  64.  
  65.      TARGETS : DEPENDENCIES
  66.              COMMAND
  67.              ...
  68.  
  69. or like this:
  70.  
  71.      TARGETS : DEPENDENCIES ; COMMAND
  72.              COMMAND
  73.              ...
  74.  
  75.    The TARGETS are file names, separated by spaces.  Wildcard
  76. characters may be used (*note Using Wildcard Characters in File Names:
  77. Wildcards.) and a name of the form `A(M)' represents member M in
  78. archive file A (*note Archive Members as Targets: Archive Members.).
  79. Usually there is only one target per rule, but occasionally there is a
  80. reason to have more (*note Multiple Targets in a Rule: Multiple
  81. Targets.).
  82.  
  83.    The COMMAND lines start with a tab character.  The first command may
  84. appear on the line after the dependencies, with a tab character, or may
  85. appear on the same line, with a semicolon.  Either way, the effect is
  86. the same.  *Note Writing the Commands in Rules: Commands.
  87.  
  88.    Because dollar signs are used to start variable references, if you
  89. really want a dollar sign in a rule you must write two of them, `$$'
  90. (*note How to Use Variables: Using Variables.).  You may split a long
  91. line by inserting a backslash followed by a newline, but this is not
  92. required, as `make' places no limit on the length of a line in a
  93. makefile.
  94.  
  95.    A rule tells `make' two things: when the targets are out of date,
  96. and how to update them when necessary.
  97.  
  98.    The criterion for being out of date is specified in terms of the
  99. DEPENDENCIES, which consist of file names separated by spaces.
  100. (Wildcards and archive members (*note Archives::.) are allowed here
  101. too.) A target is out of date if it does not exist or if it is older
  102. than any of the dependencies (by comparison of last-modification
  103. times).  The idea is that the contents of the target file are computed
  104. based on information in the dependencies, so if any of the dependencies
  105. changes, the contents of the existing target file are no longer
  106. necessarily valid.
  107.  
  108.    How to update is specified by COMMANDS.  These are lines to be
  109. executed by the shell (normally `sh'), but with some extra features
  110. (*note Writing the Commands in Rules: Commands.).
  111.  
  112. File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Rule Syntax,  Up: Rules
  113.  
  114. Using Wildcard Characters in File Names
  115. =======================================
  116.  
  117.    A single file name can specify many files using "wildcard
  118. characters".  The wildcard characters in `make' are `*', `?' and
  119. `[...]', the same as in the Bourne shell.  For example, `*.c' specifies
  120. a list of all the files (in the working directory) whose names end in
  121. `.c'.
  122.  
  123.    The character `~' at the beginning of a file name also has special
  124. significance.  If alone, or followed by a slash, it represents your home
  125. directory.  For example `~/bin' expands to `/home/you/bin'.  If the `~'
  126. is followed by a word, the string represents the home directory of the
  127. user named by that word.  For example `~john/bin' expands to
  128. `/home/john/bin'.  On systems which don't have a home directory for
  129. each user (such as MS-DOS or MS-Windows), this functionality can be
  130. simulated by setting the environment variable HOME.
  131.  
  132.    Wildcard expansion happens automatically in targets, in dependencies,
  133. and in commands (where the shell does the expansion).  In other
  134. contexts, wildcard expansion happens only if you request it explicitly
  135. with the `wildcard' function.
  136.  
  137.    The special significance of a wildcard character can be turned off by
  138. preceding it with a backslash.  Thus, `foo\*bar' would refer to a
  139. specific file whose name consists of `foo', an asterisk, and `bar'.
  140.  
  141. * Menu:
  142.  
  143. * Wildcard Examples::           Several examples
  144. * Wildcard Pitfall::            Problems to avoid.
  145. * Wildcard Function::           How to cause wildcard expansion where
  146.                                   it does not normally take place.
  147.  
  148. File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Up: Wildcards
  149.  
  150. Wildcard Examples
  151. -----------------
  152.  
  153.    Wildcards can be used in the commands of a rule, where they are
  154. expanded by the shell.  For example, here is a rule to delete all the
  155. object files:
  156.  
  157.      clean:
  158.              rm -f *.o
  159.  
  160.    Wildcards are also useful in the dependencies of a rule.  With the
  161. following rule in the makefile, `make print' will print all the `.c'
  162. files that have changed since the last time you printed them:
  163.  
  164.      print: *.c
  165.              lpr -p $?
  166.              touch print
  167.  
  168. This rule uses `print' as an empty target file; see *Note Empty Target
  169. Files to Record Events: Empty Targets.  (The automatic variable `$?' is
  170. used to print only those files that have changed; see *Note Automatic
  171. Variables: Automatic.)
  172.  
  173.    Wildcard expansion does not happen when you define a variable.
  174. Thus, if you write this:
  175.  
  176.      objects = *.o
  177.  
  178. then the value of the variable `objects' is the actual string `*.o'.
  179. However, if you use the value of `objects' in a target, dependency or
  180. command, wildcard expansion will take place at that time.  To set
  181. `objects' to the expansion, instead use:
  182.  
  183.      objects := $(wildcard *.o)
  184.  
  185. *Note Wildcard Function::.
  186.  
  187. File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
  188.  
  189. Pitfalls of Using Wildcards
  190. ---------------------------
  191.  
  192.    Now here is an example of a naive way of using wildcard expansion,
  193. that does not do what you would intend.  Suppose you would like to say
  194. that the executable file `foo' is made from all the object files in the
  195. directory, and you write this:
  196.  
  197.      objects = *.o
  198.      
  199.      foo : $(objects)
  200.              cc -o foo $(CFLAGS) $(objects)
  201.  
  202. The value of `objects' is the actual string `*.o'.  Wildcard expansion
  203. happens in the rule for `foo', so that each *existing* `.o' file
  204. becomes a dependency of `foo' and will be recompiled if necessary.
  205.  
  206.    But what if you delete all the `.o' files?  When a wildcard matches
  207. no files, it is left as it is, so then `foo' will depend on the
  208. oddly-named file `*.o'.  Since no such file is likely to exist, `make'
  209. will give you an error saying it cannot figure out how to make `*.o'.
  210. This is not what you want!
  211.  
  212.    Actually it is possible to obtain the desired result with wildcard
  213. expansion, but you need more sophisticated techniques, including the
  214. `wildcard' function and string substitution.  *Note The Function
  215. `wildcard': Wildcard Function.
  216.  
  217.    Microsoft operating systems (MS-DOS and MS-Windows) use backslashes
  218. to separate directories in pathnames, like so:
  219.  
  220.        c:\foo\bar\baz.c
  221.  
  222.    This is equivalent to the Unix-style `c:/foo/bar/baz.c' (the `c:'
  223. part is the so-called drive letter).  When `make' runs on these
  224. systems, it supports backslashes as well as the Unix-style forward
  225. slashes in pathnames.  However, this support does *not* include the
  226. wildcard expansion, where backslash is a quote character.  Therefore,
  227. you *must* use Unix-style slashes in these cases.
  228.  
  229. File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
  230.  
  231. The Function `wildcard'
  232. -----------------------
  233.  
  234.    Wildcard expansion happens automatically in rules.  But wildcard
  235. expansion does not normally take place when a variable is set, or
  236. inside the arguments of a function.  If you want to do wildcard
  237. expansion in such places, you need to use the `wildcard' function, like
  238. this:
  239.  
  240.      $(wildcard PATTERN...)
  241.  
  242. This string, used anywhere in a makefile, is replaced by a
  243. space-separated list of names of existing files that match one of the
  244. given file name patterns.  If no existing file name matches a pattern,
  245. then that pattern is omitted from the output of the `wildcard'
  246. function.  Note that this is different from how unmatched wildcards
  247. behave in rules, where they are used verbatim rather than ignored
  248. (*note Wildcard Pitfall::.).
  249.  
  250.    One use of the `wildcard' function is to get a list of all the C
  251. source files in a directory, like this:
  252.  
  253.      $(wildcard *.c)
  254.  
  255.    We can change the list of C source files into a list of object files
  256. by replacing the `.c' suffix with `.o' in the result, like this:
  257.  
  258.      $(patsubst %.c,%.o,$(wildcard *.c))
  259.  
  260. (Here we have used another function, `patsubst'.  *Note Functions for
  261. String Substitution and Analysis: Text Functions.)
  262.  
  263.    Thus, a makefile to compile all C source files in the directory and
  264. then link them together could be written as follows:
  265.  
  266.      objects := $(patsubst %.c,%.o,$(wildcard *.c))
  267.      
  268.      foo : $(objects)
  269.              cc -o foo $(objects)
  270.  
  271. (This takes advantage of the implicit rule for compiling C programs, so
  272. there is no need to write explicit rules for compiling the files.
  273. *Note The Two Flavors of Variables: Flavors, for an explanation of
  274. `:=', which is a variant of `='.)
  275.  
  276. File: make.info,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
  277.  
  278. Searching Directories for Dependencies
  279. ======================================
  280.  
  281.    For large systems, it is often desirable to put sources in a separate
  282. directory from the binaries.  The "directory search" features of `make'
  283. facilitate this by searching several directories automatically to find
  284. a dependency.  When you redistribute the files among directories, you
  285. do not need to change the individual rules, just the search paths.
  286.  
  287. * Menu:
  288.  
  289. * General Search::              Specifying a search path that applies
  290.                                   to every dependency.
  291. * Selective Search::            Specifying a search path
  292.                                   for a specified class of names.
  293. * Search Algorithm::            When and how search paths are applied.
  294. * Commands/Search::             How to write shell commands that work together
  295.                                   with search paths.
  296. * Implicit/Search::             How search paths affect implicit rules.
  297. * Libraries/Search::            Directory search for link libraries.
  298.  
  299. File: make.info,  Node: General Search,  Next: Selective Search,  Up: Directory Search
  300.  
  301. `VPATH': Search Path for All Dependencies
  302. -----------------------------------------
  303.  
  304.    The value of the `make' variable `VPATH' specifies a list of
  305. directories that `make' should search.  Most often, the directories are
  306. expected to contain dependency files that are not in the current
  307. directory; however, `VPATH' specifies a search list that `make' applies
  308. for all files, including files which are targets of rules.
  309.  
  310.    Thus, if a file that is listed as a target or dependency does not
  311. exist in the current directory, `make' searches the directories listed
  312. in `VPATH' for a file with that name.  If a file is found in one of
  313. them, that file may become the dependency (see below).  Rules may then
  314. specify the names of files in the dependency list as if they all
  315. existed in the current directory.  *Note Writing Shell Commands with
  316. Directory Search: Commands/Search.
  317.  
  318.    In the `VPATH' variable, directory names are separated by colons or
  319. blanks.  The order in which directories are listed is the order followed
  320. by `make' in its search.  (On MS-DOS and MS-Windows, semi-colons are
  321. used as separators of directory names in `VPATH', since the colon can
  322. be used in the pathname itself, after the drive letter.)
  323.  
  324.    For example,
  325.  
  326.      VPATH = src:../headers
  327.  
  328. specifies a path containing two directories, `src' and `../headers',
  329. which `make' searches in that order.
  330.  
  331.    With this value of `VPATH', the following rule,
  332.  
  333.      foo.o : foo.c
  334.  
  335. is interpreted as if it were written like this:
  336.  
  337.      foo.o : src/foo.c
  338.  
  339. assuming the file `foo.c' does not exist in the current directory but
  340. is found in the directory `src'.
  341.  
  342. File: make.info,  Node: Selective Search,  Next: Search Algorithm,  Prev: General Search,  Up: Directory Search
  343.  
  344. The `vpath' Directive
  345. ---------------------
  346.  
  347.    Similar to the `VPATH' variable, but more selective, is the `vpath'
  348. directive (note lower case), which allows you to specify a search path
  349. for a particular class of file names: those that match a particular
  350. pattern.  Thus you can supply certain search directories for one class
  351. of file names and other directories (or none) for other file names.
  352.  
  353.    There are three forms of the `vpath' directive:
  354.  
  355. `vpath PATTERN DIRECTORIES'
  356.      Specify the search path DIRECTORIES for file names that match
  357.      PATTERN.
  358.  
  359.      The search path, DIRECTORIES, is a list of directories to be
  360.      searched, separated by colons (semi-colons on MS-DOS and
  361.      MS-Windows) or blanks, just like the search path used in the
  362.      `VPATH' variable.
  363.  
  364. `vpath PATTERN'
  365.      Clear out the search path associated with PATTERN.
  366.  
  367. `vpath'
  368.      Clear all search paths previously specified with `vpath'
  369.      directives.
  370.  
  371.    A `vpath' pattern is a string containing a `%' character.  The
  372. string must match the file name of a dependency that is being searched
  373. for, the `%' character matching any sequence of zero or more characters
  374. (as in pattern rules; *note Defining and Redefining Pattern Rules:
  375. Pattern Rules.).  For example, `%.h' matches files that end in `.h'.
  376. (If there is no `%', the pattern must match the dependency exactly,
  377. which is not useful very often.)
  378.  
  379.    `%' characters in a `vpath' directive's pattern can be quoted with
  380. preceding backslashes (`\').  Backslashes that would otherwise quote
  381. `%' characters can be quoted with more backslashes.  Backslashes that
  382. quote `%' characters or other backslashes are removed from the pattern
  383. before it is compared to file names.  Backslashes that are not in
  384. danger of quoting `%' characters go unmolested.
  385.  
  386.    When a dependency fails to exist in the current directory, if the
  387. PATTERN in a `vpath' directive matches the name of the dependency file,
  388. then the DIRECTORIES in that directive are searched just like (and
  389. before) the directories in the `VPATH' variable.
  390.  
  391.    For example,
  392.  
  393.      vpath %.h ../headers
  394.  
  395. tells `make' to look for any dependency whose name ends in `.h' in the
  396. directory `../headers' if the file is not found in the current
  397. directory.
  398.  
  399.    If several `vpath' patterns match the dependency file's name, then
  400. `make' processes each matching `vpath' directive one by one, searching
  401. all the directories mentioned in each directive.  `make' handles
  402. multiple `vpath' directives in the order in which they appear in the
  403. makefile; multiple directives with the same pattern are independent of
  404. each other.
  405.  
  406.    Thus,
  407.  
  408.      vpath %.c foo
  409.      vpath %   blish
  410.      vpath %.c bar
  411.  
  412. will look for a file ending in `.c' in `foo', then `blish', then `bar',
  413. while
  414.  
  415.      vpath %.c foo:bar
  416.      vpath %   blish
  417.  
  418. will look for a file ending in `.c' in `foo', then `bar', then `blish'.
  419.  
  420. File: make.info,  Node: Search Algorithm,  Next: Commands/Search,  Prev: Selective Search,  Up: Directory Search
  421.  
  422. How Directory Searches are Performed
  423. ------------------------------------
  424.  
  425.    When a dependency is found through directory search, regardless of
  426. type (general or selective), the pathname located may not be the one
  427. that `make' actually provides you in the dependency list.  Sometimes
  428. the path discovered through directory search is thrown away.
  429.  
  430.    The algorithm `make' uses to decide whether to keep or abandon a
  431. path found via directory search is as follows:
  432.  
  433.   1. If a target file does not exist at the path specified in the
  434.      makefile, directory search is performed.
  435.  
  436.   2. If the directory search is successful, that path is kept and this
  437.      file is tentatively stored as the target.
  438.  
  439.   3. All dependencies of this target are examined using this same
  440.      method.
  441.  
  442.   4. After processing the dependencies, the target may or may not need
  443.      to be rebuilt:
  444.  
  445.        a. If the target does *not* need to be rebuilt, the path to the
  446.           file found during directory search is used for any dependency
  447.           lists which contain this target.  In short, if `make' doesn't
  448.           need to rebuild the target then you use the path found via
  449.           directory search.
  450.  
  451.        b. If the target *does* need to be rebuilt (is out-of-date), the
  452.           pathname found during directory search is *thrown away*, and
  453.           the target is rebuilt using the file name specified in the
  454.           makefile.  In short, if `make' must rebuild, then the target
  455.           is rebuilt locally, not in the directory found via directory
  456.           search.
  457.  
  458.    This algorithm may seem complex, but in practice it is quite often
  459. exactly what you want.
  460.  
  461.    Other versions of `make' use a simpler algorithm: if the file does
  462. not exist, and it is found via directory search, then that pathname is
  463. always used whether or not the target needs to be built.  Thus, if the
  464. target is rebuilt it is created at the pathname discovered during
  465. directory search.
  466.  
  467.    If, in fact, this is the behavior you want for some or all of your
  468. directories, you can use the `GPATH' variable to indicate this to
  469. `make'.
  470.  
  471.    `GPATH' has the same syntax and format as `VPATH' (that is, a space-
  472. or colon-delimited list of pathnames).  If an out-of-date target is
  473. found by directory search in a directory that also appears in `GPATH',
  474. then that pathname is not thrown away.  The target is rebuilt using the
  475. expanded path.
  476.  
  477. File: make.info,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Search Algorithm,  Up: Directory Search
  478.  
  479. Writing Shell Commands with Directory Search
  480. --------------------------------------------
  481.  
  482.    When a dependency is found in another directory through directory
  483. search, this cannot change the commands of the rule; they will execute
  484. as written.  Therefore, you must write the commands with care so that
  485. they will look for the dependency in the directory where `make' finds
  486. it.
  487.  
  488.    This is done with the "automatic variables" such as `$^' (*note
  489. Automatic Variables: Automatic.).  For instance, the value of `$^' is a
  490. list of all the dependencies of the rule, including the names of the
  491. directories in which they were found, and the value of `$@' is the
  492. target.  Thus:
  493.  
  494.      foo.o : foo.c
  495.              cc -c $(CFLAGS) $^ -o $@
  496.  
  497. (The variable `CFLAGS' exists so you can specify flags for C
  498. compilation by implicit rules; we use it here for consistency so it will
  499. affect all C compilations uniformly; *note Variables Used by Implicit
  500. Rules: Implicit Variables..)
  501.  
  502.    Often the dependencies include header files as well, which you do not
  503. want to mention in the commands.  The automatic variable `$<' is just
  504. the first dependency:
  505.  
  506.      VPATH = src:../headers
  507.      foo.o : foo.c defs.h hack.h
  508.              cc -c $(CFLAGS) $< -o $@
  509.  
  510. File: make.info,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
  511.  
  512. Directory Search and Implicit Rules
  513. -----------------------------------
  514.  
  515.    The search through the directories specified in `VPATH' or with
  516. `vpath' also happens during consideration of implicit rules (*note
  517. Using Implicit Rules: Implicit Rules.).
  518.  
  519.    For example, when a file `foo.o' has no explicit rule, `make'
  520. considers implicit rules, such as the built-in rule to compile `foo.c'
  521. if that file exists.  If such a file is lacking in the current
  522. directory, the appropriate directories are searched for it.  If `foo.c'
  523. exists (or is mentioned in the makefile) in any of the directories, the
  524. implicit rule for C compilation is applied.
  525.  
  526.    The commands of implicit rules normally use automatic variables as a
  527. matter of necessity; consequently they will use the file names found by
  528. directory search with no extra effort.
  529.  
  530. File: make.info,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
  531.  
  532. Directory Search for Link Libraries
  533. -----------------------------------
  534.  
  535.    Directory search applies in a special way to libraries used with the
  536. linker.  This special feature comes into play when you write a
  537. dependency whose name is of the form `-lNAME'.  (You can tell something
  538. strange is going on here because the dependency is normally the name of
  539. a file, and the *file name* of the library looks like `libNAME.a', not
  540. like `-lNAME'.)
  541.  
  542.    When a dependency's name has the form `-lNAME', `make' handles it
  543. specially by searching for the file `libNAME.a' in the current
  544. directory, in directories specified by matching `vpath' search paths
  545. and the `VPATH' search path, and then in the directories `/lib',
  546. `/usr/lib', and `PREFIX/lib' (normally `/usr/local/lib', but
  547. MS-DOS/MS-Windows versions of `make' behave as if PREFIX is defined to
  548. be the root of the DJGPP installation tree).
  549.  
  550.    For example,
  551.  
  552.      foo : foo.c -lcurses
  553.              cc $^ -o $@
  554.  
  555. would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be
  556. executed when `foo' is older than `foo.c' or than
  557. `/usr/lib/libcurses.a'.
  558.  
  559. File: make.info,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
  560.  
  561. Phony Targets
  562. =============
  563.  
  564.    A phony target is one that is not really the name of a file.  It is
  565. just a name for some commands to be executed when you make an explicit
  566. request.  There are two reasons to use a phony target: to avoid a
  567. conflict with a file of the same name, and to improve performance.
  568.  
  569.    If you write a rule whose commands will not create the target file,
  570. the commands will be executed every time the target comes up for
  571. remaking.  Here is an example:
  572.  
  573.      clean:
  574.              rm *.o temp
  575.  
  576. Because the `rm' command does not create a file named `clean', probably
  577. no such file will ever exist.  Therefore, the `rm' command will be
  578. executed every time you say `make clean'.
  579.  
  580.    The phony target will cease to work if anything ever does create a
  581. file named `clean' in this directory.  Since it has no dependencies, the
  582. file `clean' would inevitably be considered up to date, and its
  583. commands would not be executed.  To avoid this problem, you can
  584. explicitly declare the target to be phony, using the special target
  585. `.PHONY' (*note Special Built-in Target Names: Special Targets.) as
  586. follows:
  587.  
  588.      .PHONY : clean
  589.  
  590. Once this is done, `make clean' will run the commands regardless of
  591. whether there is a file named `clean'.
  592.  
  593.    Since it knows that phony targets do not name actual files that
  594. could be remade from other files, `make' skips the implicit rule search
  595. for phony targets (*note Implicit Rules::.).  This is why declaring a
  596. target phony is good for performance, even if you are not worried about
  597. the actual file existing.
  598.  
  599.    Thus, you first write the line that states that `clean' is a phony
  600. target, then you write the rule, like this:
  601.  
  602.      .PHONY: clean
  603.      clean:
  604.              rm *.o temp
  605.  
  606.    A phony target should not be a dependency of a real target file; if
  607. it is, its commands are run every time `make' goes to update that file.
  608. As long as a phony target is never a dependency of a real target, the
  609. phony target commands will be executed only when the phony target is a
  610. specified goal (*note Arguments to Specify the Goals: Goals.).
  611.  
  612.    Phony targets can have dependencies.  When one directory contains
  613. multiple programs, it is most convenient to describe all of the
  614. programs in one makefile `./Makefile'.  Since the target remade by
  615. default will be the first one in the makefile, it is common to make
  616. this a phony target named `all' and give it, as dependencies, all the
  617. individual programs.  For example:
  618.  
  619.      all : prog1 prog2 prog3
  620.      .PHONY : all
  621.      
  622.      prog1 : prog1.o utils.o
  623.              cc -o prog1 prog1.o utils.o
  624.      
  625.      prog2 : prog2.o
  626.              cc -o prog2 prog2.o
  627.      
  628.      prog3 : prog3.o sort.o utils.o
  629.              cc -o prog3 prog3.o sort.o utils.o
  630.  
  631. Now you can say just `make' to remake all three programs, or specify as
  632. arguments the ones to remake (as in `make prog1 prog3').
  633.  
  634.    When one phony target is a dependency of another, it serves as a
  635. subroutine of the other.  For example, here `make cleanall' will delete
  636. the object files, the difference files, and the file `program':
  637.  
  638.      .PHONY: cleanall cleanobj cleandiff
  639.      
  640.      cleanall : cleanobj cleandiff
  641.              rm program
  642.      
  643.      cleanobj :
  644.              rm *.o
  645.      
  646.      cleandiff :
  647.              rm *.diff
  648.  
  649. File: make.info,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
  650.  
  651. Rules without Commands or Dependencies
  652. ======================================
  653.  
  654.    If a rule has no dependencies or commands, and the target of the rule
  655. is a nonexistent file, then `make' imagines this target to have been
  656. updated whenever its rule is run.  This implies that all targets
  657. depending on this one will always have their commands run.
  658.  
  659.    An example will illustrate this:
  660.  
  661.      clean: FORCE
  662.              rm $(objects)
  663.      FORCE:
  664.  
  665.    Here the target `FORCE' satisfies the special conditions, so the
  666. target `clean' that depends on it is forced to run its commands.  There
  667. is nothing special about the name `FORCE', but that is one name
  668. commonly used this way.
  669.  
  670.    As you can see, using `FORCE' this way has the same results as using
  671. `.PHONY: clean'.
  672.  
  673.    Using `.PHONY' is more explicit and more efficient.  However, other
  674. versions of `make' do not support `.PHONY'; thus `FORCE' appears in
  675. many makefiles.  *Note Phony Targets::.
  676.  
  677. File: make.info,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
  678.  
  679. Empty Target Files to Record Events
  680. ===================================
  681.  
  682.    The "empty target" is a variant of the phony target; it is used to
  683. hold commands for an action that you request explicitly from time to
  684. time.  Unlike a phony target, this target file can really exist; but
  685. the file's contents do not matter, and usually are empty.
  686.  
  687.    The purpose of the empty target file is to record, with its
  688. last-modification time, when the rule's commands were last executed.  It
  689. does so because one of the commands is a `touch' command to update the
  690. target file.
  691.  
  692.    The empty target file must have some dependencies.  When you ask to
  693. remake the empty target, the commands are executed if any dependency is
  694. more recent than the target; in other words, if a dependency has
  695. changed since the last time you remade the target.  Here is an example:
  696.  
  697.      print: foo.c bar.c
  698.              lpr -p $?
  699.              touch print
  700.  
  701. With this rule, `make print' will execute the `lpr' command if either
  702. source file has changed since the last `make print'.  The automatic
  703. variable `$?' is used to print only those files that have changed
  704. (*note Automatic Variables: Automatic.).
  705.  
  706. File: make.info,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
  707.  
  708. Special Built-in Target Names
  709. =============================
  710.  
  711.    Certain names have special meanings if they appear as targets.
  712.  
  713. `.PHONY'
  714.      The dependencies of the special target `.PHONY' are considered to
  715.      be phony targets.  When it is time to consider such a target,
  716.      `make' will run its commands unconditionally, regardless of
  717.      whether a file with that name exists or what its last-modification
  718.      time is.  *Note Phony Targets: Phony Targets.
  719.  
  720. `.SUFFIXES'
  721.      The dependencies of the special target `.SUFFIXES' are the list of
  722.      suffixes to be used in checking for suffix rules.  *Note
  723.      Old-Fashioned Suffix Rules: Suffix Rules.
  724.  
  725. `.DEFAULT'
  726.      The commands specified for `.DEFAULT' are used for any target for
  727.      which no rules are found (either explicit rules or implicit rules).
  728.      *Note Last Resort::.  If `.DEFAULT' commands are specified, every
  729.      file mentioned as a dependency, but not as a target in a rule,
  730.      will have these commands executed on its behalf.  *Note Implicit
  731.      Rule Search Algorithm: Implicit Rule Search.
  732.  
  733. `.PRECIOUS'
  734.      The targets which `.PRECIOUS' depends on are given the following
  735.      special treatment: if `make' is killed or interrupted during the
  736.      execution of their commands, the target is not deleted.  *Note
  737.      Interrupting or Killing `make': Interrupts.  Also, if the target
  738.      is an intermediate file, it will not be deleted after it is no
  739.      longer needed, as is normally done.  *Note Chains of Implicit
  740.      Rules: Chained Rules.
  741.  
  742.      You can also list the target pattern of an implicit rule (such as
  743.      `%.o') as a dependency file of the special target `.PRECIOUS' to
  744.      preserve intermediate files created by rules whose target patterns
  745.      match that file's name.
  746.  
  747. `.INTERMEDIATE'
  748.      The targets which `.INTERMEDIATE' depends on are treated as
  749.      intermediate files.  *Note Chains of Implicit Rules: Chained Rules.
  750.      `.INTERMEDIATE' with no dependencies marks all file targets
  751.      mentioned in the makefile as intermediate.
  752.  
  753. `.SECONDARY'
  754.      The targets which `.SECONDARY' depends on are treated as
  755.      intermediate files, except that they are never automatically
  756.      deleted.  *Note Chains of Implicit Rules: Chained Rules.
  757.  
  758.      `.SECONDARY' with no dependencies marks all file targets mentioned
  759.      in the makefile as secondary.
  760.  
  761. `.IGNORE'
  762.      If you specify dependencies for `.IGNORE', then `make' will ignore
  763.      errors in execution of the commands run for those particular
  764.      files.  The commands for `.IGNORE' are not meaningful.
  765.  
  766.      If mentioned as a target with no dependencies, `.IGNORE' says to
  767.      ignore errors in execution of commands for all files.  This usage
  768.      of `.IGNORE' is supported only for historical compatibility.  Since
  769.      this affects every command in the makefile, it is not very useful;
  770.      we recommend you use the more selective ways to ignore errors in
  771.      specific commands.  *Note Errors in Commands: Errors.
  772.  
  773. `.SILENT'
  774.      If you specify dependencies for `.SILENT', then `make' will not
  775.      the print commands to remake those particular files before
  776.      executing them.  The commands for `.SILENT' are not meaningful.
  777.  
  778.      If mentioned as a target with no dependencies, `.SILENT' says not
  779.      to print any commands before executing them.  This usage of
  780.      `.SILENT' is supported only for historical compatibility.  We
  781.      recommend you use the more selective ways to silence specific
  782.      commands.  *Note Command Echoing: Echoing.  If you want to silence
  783.      all commands for a particular run of `make', use the `-s' or
  784.      `--silent' option (*note Options Summary::.).
  785.  
  786. `.EXPORT_ALL_VARIABLES'
  787.      Simply by being mentioned as a target, this tells `make' to export
  788.      all variables to child processes by default.  *Note Communicating
  789.      Variables to a Sub-`make': Variables/Recursion.
  790.  
  791.    Any defined implicit rule suffix also counts as a special target if
  792. it appears as a target, and so does the concatenation of two suffixes,
  793. such as `.c.o'.  These targets are suffix rules, an obsolete way of
  794. defining implicit rules (but a way still widely used).  In principle,
  795. any target name could be special in this way if you break it in two and
  796. add both pieces to the suffix list.  In practice, suffixes normally
  797. begin with `.', so these special target names also begin with `.'.
  798. *Note Old-Fashioned Suffix Rules: Suffix Rules.
  799.  
  800. File: make.info,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
  801.  
  802. Multiple Targets in a Rule
  803. ==========================
  804.  
  805.    A rule with multiple targets is equivalent to writing many rules,
  806. each with one target, and all identical aside from that.  The same
  807. commands apply to all the targets, but their effects may vary because
  808. you can substitute the actual target name into the command using `$@'.
  809. The rule contributes the same dependencies to all the targets also.
  810.  
  811.    This is useful in two cases.
  812.  
  813.    * You want just dependencies, no commands.  For example:
  814.  
  815.           kbd.o command.o files.o: command.h
  816.  
  817.      gives an additional dependency to each of the three object files
  818.      mentioned.
  819.  
  820.    * Similar commands work for all the targets.  The commands do not
  821.      need to be absolutely identical, since the automatic variable `$@'
  822.      can be used to substitute the particular target to be remade into
  823.      the commands (*note Automatic Variables: Automatic.).  For example:
  824.  
  825.           bigoutput littleoutput : text.g
  826.                   generate text.g -$(subst output,,$@) > $@
  827.  
  828.      is equivalent to
  829.  
  830.           bigoutput : text.g
  831.                   generate text.g -big > bigoutput
  832.           littleoutput : text.g
  833.                   generate text.g -little > littleoutput
  834.  
  835.      Here we assume the hypothetical program `generate' makes two types
  836.      of output, one if given `-big' and one if given `-little'.  *Note
  837.      Functions for String Substitution and Analysis: Text Functions,
  838.      for an explanation of the `subst' function.
  839.  
  840.    Suppose you would like to vary the dependencies according to the
  841. target, much as the variable `$@' allows you to vary the commands.  You
  842. cannot do this with multiple targets in an ordinary rule, but you can
  843. do it with a "static pattern rule".  *Note Static Pattern Rules: Static
  844. Pattern.
  845.  
  846. File: make.info,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
  847.  
  848. Multiple Rules for One Target
  849. =============================
  850.  
  851.    One file can be the target of several rules.  All the dependencies
  852. mentioned in all the rules are merged into one list of dependencies for
  853. the target.  If the target is older than any dependency from any rule,
  854. the commands are executed.
  855.  
  856.    There can only be one set of commands to be executed for a file.  If
  857. more than one rule gives commands for the same file, `make' uses the
  858. last set given and prints an error message.  (As a special case, if the
  859. file's name begins with a dot, no error message is printed.  This odd
  860. behavior is only for compatibility with other implementations of
  861. `make'.) There is no reason to write your makefiles this way; that is
  862. why `make' gives you an error message.
  863.  
  864.    An extra rule with just dependencies can be used to give a few extra
  865. dependencies to many files at once.  For example, one usually has a
  866. variable named `objects' containing a list of all the compiler output
  867. files in the system being made.  An easy way to say that all of them
  868. must be recompiled if `config.h' changes is to write the following:
  869.  
  870.      objects = foo.o bar.o
  871.      foo.o : defs.h
  872.      bar.o : defs.h test.h
  873.      $(objects) : config.h
  874.  
  875.    This could be inserted or taken out without changing the rules that
  876. really specify how to make the object files, making it a convenient
  877. form to use if you wish to add the additional dependency intermittently.
  878.  
  879.    Another wrinkle is that the additional dependencies could be
  880. specified with a variable that you set with a command argument to `make'
  881. (*note Overriding Variables: Overriding.).  For example,
  882.  
  883.      extradeps=
  884.      $(objects) : $(extradeps)
  885.  
  886. means that the command `make extradeps=foo.h' will consider `foo.h' as
  887. a dependency of each object file, but plain `make' will not.
  888.  
  889.    If none of the explicit rules for a target has commands, then `make'
  890. searches for an applicable implicit rule to find some commands *note
  891. Using Implicit Rules: Implicit Rules.).
  892.  
  893. File: make.info,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
  894.  
  895. Static Pattern Rules
  896. ====================
  897.  
  898.    "Static pattern rules" are rules which specify multiple targets and
  899. construct the dependency names for each target based on the target name.
  900. They are more general than ordinary rules with multiple targets because
  901. the targets do not have to have identical dependencies.  Their
  902. dependencies must be *analogous*, but not necessarily *identical*.
  903.  
  904. * Menu:
  905.  
  906. * Static Usage::                The syntax of static pattern rules.
  907. * Static versus Implicit::      When are they better than implicit rules?
  908.  
  909. File: make.info,  Node: Static Usage,  Next: Static versus Implicit,  Up: Static Pattern
  910.  
  911. Syntax of Static Pattern Rules
  912. ------------------------------
  913.  
  914.    Here is the syntax of a static pattern rule:
  915.  
  916.      TARGETS ...: TARGET-PATTERN: DEP-PATTERNS ...
  917.              COMMANDS
  918.              ...
  919.  
  920. The TARGETS list specifies the targets that the rule applies to.  The
  921. targets can contain wildcard characters, just like the targets of
  922. ordinary rules (*note Using Wildcard Characters in File Names:
  923. Wildcards.).
  924.  
  925.    The TARGET-PATTERN and DEP-PATTERNS say how to compute the
  926. dependencies of each target.  Each target is matched against the
  927. TARGET-PATTERN to extract a part of the target name, called the "stem".
  928. This stem is substituted into each of the DEP-PATTERNS to make the
  929. dependency names (one from each DEP-PATTERN).
  930.  
  931.    Each pattern normally contains the character `%' just once.  When the
  932. TARGET-PATTERN matches a target, the `%' can match any part of the
  933. target name; this part is called the "stem".  The rest of the pattern
  934. must match exactly.  For example, the target `foo.o' matches the
  935. pattern `%.o', with `foo' as the stem.  The targets `foo.c' and
  936. `foo.out' do not match that pattern.
  937.  
  938.    The dependency names for each target are made by substituting the
  939. stem for the `%' in each dependency pattern.  For example, if one
  940. dependency pattern is `%.c', then substitution of the stem `foo' gives
  941. the dependency name `foo.c'.  It is legitimate to write a dependency
  942. pattern that does not contain `%'; then this dependency is the same for
  943. all targets.
  944.  
  945.    `%' characters in pattern rules can be quoted with preceding
  946. backslashes (`\').  Backslashes that would otherwise quote `%'
  947. characters can be quoted with more backslashes.  Backslashes that quote
  948. `%' characters or other backslashes are removed from the pattern before
  949. it is compared to file names or has a stem substituted into it.
  950. Backslashes that are not in danger of quoting `%' characters go
  951. unmolested.  For example, the pattern `the\%weird\\%pattern\\' has
  952. `the%weird\' preceding the operative `%' character, and `pattern\\'
  953. following it.  The final two backslashes are left alone because they
  954. cannot affect any `%' character.
  955.  
  956.    Here is an example, which compiles each of `foo.o' and `bar.o' from
  957. the corresponding `.c' file:
  958.  
  959.      objects = foo.o bar.o
  960.      
  961.      all: $(objects)
  962.      
  963.      $(objects): %.o: %.c
  964.              $(CC) -c $(CFLAGS) $< -o $@
  965.  
  966. Here `$<' is the automatic variable that holds the name of the
  967. dependency and `$@' is the automatic variable that holds the name of
  968. the target; see *Note Automatic Variables: Automatic.
  969.  
  970.    Each target specified must match the target pattern; a warning is
  971. issued for each target that does not.  If you have a list of files,
  972. only some of which will match the pattern, you can use the `filter'
  973. function to remove nonmatching file names (*note Functions for String
  974. Substitution and Analysis: Text Functions.):
  975.  
  976.      files = foo.elc bar.o lose.o
  977.      
  978.      $(filter %.o,$(files)): %.o: %.c
  979.              $(CC) -c $(CFLAGS) $< -o $@
  980.      $(filter %.elc,$(files)): %.elc: %.el
  981.              emacs -f batch-byte-compile $<
  982.  
  983. In this example the result of `$(filter %.o,$(files))' is `bar.o
  984. lose.o', and the first static pattern rule causes each of these object
  985. files to be updated by compiling the corresponding C source file.  The
  986. result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
  987. from `foo.el'.
  988.  
  989.    Another example shows how to use `$*' in static pattern rules:
  990.  
  991.      bigoutput littleoutput : %output : text.g
  992.              generate text.g -$* > $@
  993.  
  994. When the `generate' command is run, `$*' will expand to the stem,
  995. either `big' or `little'.
  996.  
  997. File: make.info,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
  998.  
  999. Static Pattern Rules versus Implicit Rules
  1000. ------------------------------------------
  1001.  
  1002.    A static pattern rule has much in common with an implicit rule
  1003. defined as a pattern rule (*note Defining and Redefining Pattern Rules:
  1004. Pattern Rules.).  Both have a pattern for the target and patterns for
  1005. constructing the names of dependencies.  The difference is in how
  1006. `make' decides *when* the rule applies.
  1007.  
  1008.    An implicit rule *can* apply to any target that matches its pattern,
  1009. but it *does* apply only when the target has no commands otherwise
  1010. specified, and only when the dependencies can be found.  If more than
  1011. one implicit rule appears applicable, only one applies; the choice
  1012. depends on the order of rules.
  1013.  
  1014.    By contrast, a static pattern rule applies to the precise list of
  1015. targets that you specify in the rule.  It cannot apply to any other
  1016. target and it invariably does apply to each of the targets specified.
  1017. If two conflicting rules apply, and both have commands, that's an error.
  1018.  
  1019.    The static pattern rule can be better than an implicit rule for these
  1020. reasons:
  1021.  
  1022.    * You may wish to override the usual implicit rule for a few files
  1023.      whose names cannot be categorized syntactically but can be given
  1024.      in an explicit list.
  1025.  
  1026.    * If you cannot be sure of the precise contents of the directories
  1027.      you are using, you may not be sure which other irrelevant files
  1028.      might lead `make' to use the wrong implicit rule.  The choice
  1029.      might depend on the order in which the implicit rule search is
  1030.      done.  With static pattern rules, there is no uncertainty: each
  1031.      rule applies to precisely the targets specified.
  1032.  
  1033. File: make.info,  Node: Double-Colon,  Next: Automatic Dependencies,  Prev: Static Pattern,  Up: Rules
  1034.  
  1035. Double-Colon Rules
  1036. ==================
  1037.  
  1038.    "Double-colon" rules are rules written with `::' instead of `:'
  1039. after the target names.  They are handled differently from ordinary
  1040. rules when the same target appears in more than one rule.
  1041.  
  1042.    When a target appears in multiple rules, all the rules must be the
  1043. same type: all ordinary, or all double-colon.  If they are
  1044. double-colon, each of them is independent of the others.  Each
  1045. double-colon rule's commands are executed if the target is older than
  1046. any dependencies of that rule.  This can result in executing none, any,
  1047. or all of the double-colon rules.
  1048.  
  1049.    Double-colon rules with the same target are in fact completely
  1050. separate from one another.  Each double-colon rule is processed
  1051. individually, just as rules with different targets are processed.
  1052.  
  1053.    The double-colon rules for a target are executed in the order they
  1054. appear in the makefile.  However, the cases where double-colon rules
  1055. really make sense are those where the order of executing the commands
  1056. would not matter.
  1057.  
  1058.    Double-colon rules are somewhat obscure and not often very useful;
  1059. they provide a mechanism for cases in which the method used to update a
  1060. target differs depending on which dependency files caused the update,
  1061. and such cases are rare.
  1062.  
  1063.    Each double-colon rule should specify commands; if it does not, an
  1064. implicit rule will be used if one applies.  *Note Using Implicit Rules:
  1065. Implicit Rules.
  1066.  
  1067. File: make.info,  Node: Automatic Dependencies,  Prev: Double-Colon,  Up: Rules
  1068.  
  1069. Generating Dependencies Automatically
  1070. =====================================
  1071.  
  1072.    In the makefile for a program, many of the rules you need to write
  1073. often say only that some object file depends on some header file.  For
  1074. example, if `main.c' uses `defs.h' via an `#include', you would write:
  1075.  
  1076.      main.o: defs.h
  1077.  
  1078. You need this rule so that `make' knows that it must remake `main.o'
  1079. whenever `defs.h' changes.  You can see that for a large program you
  1080. would have to write dozens of such rules in your makefile.  And, you
  1081. must always be very careful to update the makefile every time you add
  1082. or remove an `#include'.
  1083.  
  1084.    To avoid this hassle, most modern C compilers can write these rules
  1085. for you, by looking at the `#include' lines in the source files.
  1086. Usually this is done with the `-M' option to the compiler.  For
  1087. example, the command:
  1088.  
  1089.      cc -M main.c
  1090.  
  1091. generates the output:
  1092.  
  1093.      main.o : main.c defs.h
  1094.  
  1095. Thus you no longer have to write all those rules yourself.  The
  1096. compiler will do it for you.
  1097.  
  1098.    Note that such a dependency constitutes mentioning `main.o' in a
  1099. makefile, so it can never be considered an intermediate file by implicit
  1100. rule search.  This means that `make' won't ever remove the file after
  1101. using it; *note Chains of Implicit Rules: Chained Rules..
  1102.  
  1103.    With old `make' programs, it was traditional practice to use this
  1104. compiler feature to generate dependencies on demand with a command like
  1105. `make depend'.  That command would create a file `depend' containing
  1106. all the automatically-generated dependencies; then the makefile could
  1107. use `include' to read them in (*note Include::.).
  1108.  
  1109.    In GNU `make', the feature of remaking makefiles makes this practice
  1110. obsolete--you need never tell `make' explicitly to regenerate the
  1111. dependencies, because it always regenerates any makefile that is out of
  1112. date.  *Note Remaking Makefiles::.
  1113.  
  1114.    The practice we recommend for automatic dependency generation is to
  1115. have one makefile corresponding to each source file.  For each source
  1116. file `NAME.c' there is a makefile `NAME.d' which lists what files the
  1117. object file `NAME.o' depends on.  That way only the source files that
  1118. have changed need to be rescanned to produce the new dependencies.
  1119.  
  1120.    Here is the pattern rule to generate a file of dependencies (i.e., a
  1121. makefile) called `NAME.d' from a C source file called `NAME.c':
  1122.  
  1123.      %.d: %.c
  1124.              $(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
  1125.                            | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
  1126.                            [ -s $@ ] || rm -f $@'
  1127.  
  1128. *Note Pattern Rules::, for information on defining pattern rules.  The
  1129. `-e' flag to the shell makes it exit immediately if the `$(CC)' command
  1130. fails (exits with a nonzero status).  Normally the shell exits with the
  1131. status of the last command in the pipeline (`sed' in this case), so
  1132. `make' would not notice a nonzero status from the compiler.
  1133.  
  1134.    With the GNU C compiler, you may wish to use the `-MM' flag instead
  1135. of `-M'.  This omits dependencies on system header files.  *Note
  1136. Options Controlling the Preprocessor: (gcc.info)Preprocessor Options,
  1137. for details.
  1138.  
  1139.    The purpose of the `sed' command is to translate (for example):
  1140.  
  1141.      main.o : main.c defs.h
  1142.  
  1143. into:
  1144.  
  1145.      main.o main.d : main.c defs.h
  1146.  
  1147. This makes each `.d' file depend on all the source and header files
  1148. that the corresponding `.o' file depends on.  `make' then knows it must
  1149. regenerate the dependencies whenever any of the source or header files
  1150. changes.
  1151.  
  1152.    Once you've defined the rule to remake the `.d' files, you then use
  1153. the `include' directive to read them all in.  *Note Include::.  For
  1154. example:
  1155.  
  1156.      sources = foo.c bar.c
  1157.      
  1158.      include $(sources:.c=.d)
  1159.  
  1160. (This example uses a substitution variable reference to translate the
  1161. list of source files `foo.c bar.c' into a list of dependency makefiles,
  1162. `foo.d bar.d'.  *Note Substitution Refs::, for full information on
  1163. substitution references.)  Since the `.d' files are makefiles like any
  1164. others, `make' will remake them as necessary with no further work from
  1165. you.  *Note Remaking Makefiles::.
  1166.  
  1167. File: make.info,  Node: Commands,  Next: Using Variables,  Prev: Rules,  Up: Top
  1168.  
  1169. Writing the Commands in Rules
  1170. *****************************
  1171.  
  1172.    The commands of a rule consist of shell command lines to be executed
  1173. one by one.  Each command line must start with a tab, except that the
  1174. first command line may be attached to the target-and-dependencies line
  1175. with a semicolon in between.  Blank lines and lines of just comments
  1176. may appear among the command lines; they are ignored.  (But beware, an
  1177. apparently "blank" line that begins with a tab is *not* blank!  It is an
  1178. empty command; *note Empty Commands::..)
  1179.  
  1180.    Users use many different shell programs, but commands in makefiles
  1181. are always interpreted by `/bin/sh' unless the makefile specifies
  1182. otherwise.  *Note Command Execution: Execution.
  1183.  
  1184.    The shell that is in use determines whether comments can be written
  1185. on command lines, and what syntax they use.  When the shell is
  1186. `/bin/sh', a `#' starts a comment that extends to the end of the line.
  1187. The `#' does not have to be at the beginning of a line.  Text on a line
  1188. before a `#' is not part of the comment.
  1189.  
  1190. * Menu:
  1191.  
  1192. * Echoing::                     How to control when commands are echoed.
  1193. * Execution::                   How commands are executed.
  1194. * Parallel::                    How commands can be executed in parallel.
  1195. * Errors::                      What happens after a command execution error.
  1196. * Interrupts::                  What happens when a command is interrupted.
  1197. * Recursion::                   Invoking `make' from makefiles.
  1198. * Sequences::                   Defining canned sequences of commands.
  1199. * Empty Commands::              Defining useful, do-nothing commands.
  1200.  
  1201.